package com.zlm.qsmanage.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zlm.qsmanage.common.Result;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.zlm.qsmanage.service.ICollectService;
import com.zlm.qsmanage.entity.Collect;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zlm
 * @since 2022-12-15
 */
@RestController
@RequestMapping("/collect")
public class CollectController {

@Resource
private ICollectService collectService;

// 新增或者更新
    @PostMapping
    public Result save(@RequestBody Collect collect) {
        collectService.saveOrUpdate(collect);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        collectService.removeById(id);
        return Result.success();
    }

    @PostMapping("/del/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {

    collectService.removeByIds(ids);
        return Result.success();
        }

    @GetMapping
    public Result findAll() {
        return Result.success(collectService.list());
        }

    @GetMapping("/{id}")
    public Result findOne(@PathVariable Integer id) {
        return Result.success(collectService.getById(id));
        }

    @GetMapping("/page")
    public Result findPage(@RequestParam Integer pageNum,
    @RequestParam Integer pageSize) {
        QueryWrapper<Collect> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        return Result.success(collectService.page(new Page<>(pageNum, pageSize), queryWrapper));
        }
}

